package bpm.service.impl.user.unite;

import bpm.domain.user.unite.UniteUser.OperationState;

public class BuildOperationState {
	public static OperationState buildState(OperationState old,OperationState newly){
		if(old!=null&&newly!=null){
			String oldName=old.name();
			String newName=newly.name();
			String operation=buildString(oldName, newName);
			if(operation!=null)
				return OperationState.valueOf(operation);
			else
				return null;
		}else{
			if(old==null&&newly!=null){
				return newly;
			}else if(old!=null &&newly==null){
				return old;
			}else{
				return null;
			}
		}
	}
	private static  String buildString(String oldName,String newName){
		if("ADD".equals(oldName)){
			if("UPDATE".equals(newName)){
				return "UPDATE";
			}else if("DELETE".equals(newName)){
				return "DELETE";
			}else{
				return "ADD";
			}
		}else if("UPDATE".equals(oldName)){
			if("UPDATE".equals(newName)){
				return "UPDATE";
			}else if("DELETE".equals(newName)){
				return "DELETE";
			}else{
				return "UPDATE";
			}
		}else if("DELETE".equals(oldName)){
			if("UPDATE".equals(newName)){
				return "UPDATE";
			}else if("ADD".equals(newName)){
				return "ADD";
			}else{
				return "DELETE";
			}
		}
		return null;
	}
	public static OperationState creatOpeState(String state,String versioned){
		if("0".equals(state)){
			if("1".equals(versioned)){
				return OperationState.valueOf("ADD");
			}else{
				return OperationState.valueOf("UPDATE");
			}
		}else{
			return OperationState.valueOf("DELETE");
		}
	}
}
